What is mdast-util-gfm-autolink-literal?
The mdast-util-gfm-autolink-literal npm package is a utility to support GitHub Flavored Markdown (GFM) autolink literals in mdast syntax trees. It helps parse and serialize autolink literals like URLs and email addresses directly in Markdown documents, making them clickable links without additional markup.
What are mdast-util-gfm-autolink-literal's main functionalities?
Parsing GFM Autolink Literals
This code sample demonstrates how to set up a processor using Unified with the remark-parse and remark-gfm plugins, enhanced by mdast-util-gfm-autolink-literal to automatically parse URLs written in plain text as autolink literals in the Markdown document.
import { unified } from 'unified';
import markdown from 'remark-parse';
import gfm from 'remark-gfm';
import gfmAutolinkLiteral from 'mdast-util-gfm-autolink-literal';
const processor = unified()
.use(markdown)
.use(gfm)
.use(gfmAutolinkLiteral);
const tree = processor.parse('See https://example.com for more info.');
console.log(tree);
Other packages similar to mdast-util-gfm-autolink-literal
remark-gfm
This package is a plugin for remark that supports all GFM features, including autolinks, tables, strikethrough, and task lists. It is broader in scope compared to mdast-util-gfm-autolink-literal, which specifically focuses on autolink literals.
micromark-extension-gfm-autolink-literal
Similar to mdast-util-gfm-autolink-literal, this package is a micromark extension to parse and serialize GFM autolink literals. It serves a similar purpose but is used in the micromark ecosystem, which is the underlying system for remark.
mdast-util-gfm-autolink-literal
![Chat](https://img.shields.io/badge/chat-discussions-success.svg)
Extension for mdast-util-from-markdown
and/or
mdast-util-to-markdown
to support GitHub flavored markdown
autolink literals in mdast.
When parsing (from-markdown
), must be combined with
micromark-extension-gfm-autolink-literal
.
You might want to use this package through remark-gfm
with
remark.
Install
npm:
npm install mdast-util-gfm-autolink-literal
Use
Say our script, example.js
, looks as follows:
var fromMarkdown = require('mdast-util-from-markdown')
var toMarkdown = require('mdast-util-to-markdown')
var syntax = require('micromark-extension-gfm-autolink-literal')
var autolinkLiteral = require('mdast-util-gfm-autolink-literal')
var doc = 'www.example.com, https://example.com, and contact@example.com.'
var tree = fromMarkdown(doc, {
extensions: [syntax],
mdastExtensions: [autolinkLiteral.fromMarkdown]
})
console.log(tree)
var out = toMarkdown(tree, {extensions: [autolinkLiteral.toMarkdown]})
console.log(out)
Now, running node example
yields:
{
type: 'root',
children: [
{
type: 'paragraph',
children: [
{
type: 'link',
title: null,
url: 'http://www.example.com',
children: [{type: 'text', value: 'www.example.com'}]
},
{type: 'text', value: ', '},
{
type: 'link',
title: null,
url: 'https://example.com',
children: [{type: 'text', value: 'https://example.com'}]
},
{type: 'text', value: ', and '},
{
type: 'link',
title: null,
url: 'mailto:contact@example.com',
children: [{type: 'text', value: 'contact@example.com'}]
},
{type: 'text', value: '.'}
]
}
]
}
[www.example.com](http://www.example.com), <https://example.com>, and <contact@example.com>.
API
autolinkLiteral.fromMarkdown
autolinkLiteral.toMarkdown
Note: the separate extensions are also available at
mdast-util-gfm-autolink-literal/from-markdown
and
mdast-util-gfm-autolink-literal/to-markdown
.
Support literal autolinks.
The exports are extensions, respectively
for mdast-util-from-markdown
and
mdast-util-to-markdown
.
Related
Contribute
See contributing.md
in syntax-tree/.github
for ways to get
started.
See support.md
for ways to get help.
This project has a code of conduct.
By interacting with this repository, organization, or community you agree to
abide by its terms.
License
MIT © Titus Wormer